package com.hyg.ndkapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv = findViewById(R.id.sample_text);
        tv.setText(NativeLib.stringFromJNI());

        findViewById(R.id.btn1).setOnClickListener(this);
        findViewById(R.id.btn2).setOnClickListener(this);
        findViewById(R.id.btn3).setOnClickListener(this);
    }

    boolean isStart = false;
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn1:
                RangingActivity.launch(this);
//                new Thread(new Runnable() {
//                    @Override
//                    public void run() {
//                        NativeLib.openI2CDev();
//                        isStart = true;
//                        while (isStart){
//                            NativeLib.getHeight(1);
//                            SystemClock.sleep(100);
//                        }
//                    }
//                }).start();
                break;
            case R.id.btn2:
//                isStart = false;
//                long tt = System.currentTimeMillis();
//                NativeLib.getHeight(1);
//                Log.e("hhhhh","time = " + (System.currentTimeMillis() - tt));
                break;
            case R.id.btn3:
                SerialActivity.launch(this);
                break;
        }
    }
}